<?php

namespace app\middleware;

use Closure;
// use Symfony\Component\HttpFoundation\Request;
use think\Response;
// use Symfony\Component\HttpKernel\Exception\HttpException;

class Validate
{
    /**
     * api接口数据返回结果内容的处理
     * 
     * @param $request
     * @param \Closure $next
     * @return mixed
     */
    public function handle($request, \Closure $next)
    {
        $response = $next($request);
        $e = (array) $response->getData();
        if(!isset($e['code']) && !isset($e['msg'])){
            $e = [
                'code' => 200,
                'msg' => 'Success',
                'data' => $e
            ];
        }
        $response->data($e);
        return $response;
    }
}
